home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / so91.lha / Scan / listdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-23  |  4.0 KB  |  143 lines

  1. ;/* ListDir.c - Amiga Mail simple ExAll() example.
  2. lc -cfis -v -d0 -b0 -j73 ListDir.c
  3. blink from ListDir.o to ListDir lib lib:amiga.lib ;if you don't have pragmas
  4. quit
  5.  *
  6.  * Pure code if pragmas are used.
  7.  * Tuesday, 16-Jul-91 16:21:14, Ewout
  8.  *
  9.  * Compiled with SAS/C 5.10a
  10.  */
  11. /* (c)  Copyright 1991 Commodore-Amiga, Inc.   All rights reserved.
  12. The information contained herein is subject to change without notice,
  13. and is provided "as is" without warranty of any kind, either expressed
  14. or implied.  The entire risk as to the use of this information is
  15. assumed by the user.
  16. */
  17.  
  18. #include <exec/memory.h>
  19. #include <dos/dosextens.h>
  20. #include <dos/rdargs.h>
  21. #include <dos/exall.h>
  22.  
  23. #include <clib/exec_protos.h>
  24. #include <clib/dos_protos.h>
  25.  
  26. /* undef PRAGMAS if you don't have them */
  27. #define PRAGMAS
  28. #undef PRAGMAS
  29. #ifdef PRAGMAS
  30. #include <pragmas/exec_pragmas.h>
  31. #include <pragmas/dos_pragmas.h>
  32. #else
  33. struct ExecBase *SysBase;
  34. struct DosLibrary *DOSBase;
  35.  
  36. #endif
  37.  
  38. /* Buffersize to receive filenames in */
  39. #define BUFFERSIZE 512
  40.  
  41. VOID            main(VOID);
  42.  
  43. VOID
  44. main(VOID)
  45. {
  46. #ifdef PRAGMAS
  47.     struct DosLibrary *DOSBase;
  48.  
  49. #endif
  50.     struct RDArgs  *readargs;
  51.     LONG            rargs[2];
  52.     struct ExAllControl *excontrol;
  53.     struct ExAllData *ead, *buffer;
  54.     UBYTE          *source;
  55.     BPTR            sourcelock;
  56.     BOOL            exmore;
  57.     LONG            error;
  58.  
  59. #ifndef PRAGMAS
  60.     /* set up SysBase */
  61.     SysBase = (*((struct Library **) 4));
  62. #endif
  63.  
  64.     /* Fail silently if < 37 */
  65.     if (DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37))
  66.     {
  67.  
  68.         if (readargs = ReadArgs("DIRECTORY/A", rargs, NULL))
  69.         {
  70.  
  71.             source = (UBYTE *) rargs[0];
  72.  
  73.             if (buffer = AllocMem(BUFFERSIZE, MEMF_CLEAR))
  74.             {
  75.  
  76.                 if (sourcelock = Lock(source, SHARED_LOCK))
  77.                 {
  78.                     if (excontrol = AllocDosObject(DOS_EXALLCONTROL, NULL))
  79.                     {
  80.                         excontrol->eac_LastKey = 0;
  81.  
  82.                         do
  83.                         {
  84.  
  85.                             exmore = ExAll(sourcelock,
  86.                                            buffer,
  87.                                            BUFFERSIZE,
  88.                                            ED_NAME,
  89.                                            excontrol);
  90.                             error = IoErr();
  91.                             if ((exmore == NULL &&
  92.                                 (error != ERROR_NO_MORE_ENTRIES)))
  93.                                 break;
  94.  
  95.                             if (excontrol->eac_Entries == 0)
  96.                                 continue;
  97.  
  98.                             ead = buffer;
  99.                             do
  100.                             {
  101.  
  102.                                 /* Check for CTRL-C */
  103.                                 if (SetSignal(0L, SIGBREAKF_CTRL_C) &
  104.                                         SIGBREAKF_CTRL_C)
  105.                                 {
  106.                                     error = ERROR_BREAK;
  107.                                     exmore = FALSE;
  108.                                     break;
  109.                                 }
  110.  
  111.                                 rargs[0] = (LONG) ead->ed_Name;
  112.                                 VFPrintf(Output(), "%s\n", rargs);
  113.  
  114.                                 ead = ead->ed_Next;
  115.                             } while (ead);
  116.                         } while (exmore);
  117.  
  118.                         if (error != ERROR_NO_MORE_ENTRIES)
  119.                             PrintFault(error, NULL);
  120.  
  121.                         FreeDosObject(DOS_EXALLCONTROL, excontrol);
  122.                     }
  123.                     else
  124.                         PrintFault(ERROR_NO_FREE_STORE, NULL);
  125.  
  126.                     UnLock(sourcelock);
  127.                 }
  128.                 else
  129.                     PrintFault(IoErr(), source);
  130.  
  131.                 FreeMem(buffer, BUFFERSIZE);
  132.             }
  133.             else
  134.                 PrintFault(ERROR_NO_FREE_STORE, NULL);
  135.             FreeArgs(readargs);
  136.  
  137.         }
  138.         else
  139.             PrintFault(IoErr(), NULL);
  140.         CloseLibrary((struct Library *) DOSBase);
  141.     }
  142. }
  143.